package lock.lntelligence.gjx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.aiton.administrator.shane_library.shane.ZjbBaseActivity;

import java.util.ArrayList;
import java.util.List;

import lock.lntelligence.gjx.R;
import lock.lntelligence.gjx.constant.Constant;
import lock.lntelligence.gjx.model.OpenLog;

public class OpenLogActivity extends ZjbBaseActivity implements View.OnClickListener {

    private ListView mListView_openLog;
    private List<OpenLog> openLogList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        init();
    }

    @Override
    protected void initData() {
        openLogList.add(new OpenLog("龚建雄","2016-09-09 09:28:52"));
        openLogList.add(new OpenLog("龚建雄","2016-09-09 09:24:26"));
        openLogList.add(new OpenLog("祝志雄","2016-09-09 09:18:18"));
    }

    @Override
    protected void initViews() {
        mListView_openLog.setAdapter(new MyAdapter());
    }

    @Override
    protected void setListeners() {
        findViewById(R.id.imageView_back).setOnClickListener(this);
    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {

    }

    @Override
    protected void findID() {
        mListView_openLog = (ListView) findViewById(R.id.listView_openLog);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.imageView_back:
                finishTo();
                break;
        }
    }

    class MyAdapter extends BaseAdapter {
     
             @Override
             public int getCount() {
                 return openLogList.size();
             }
     
             @Override
             public Object getItem(int position) {
                 return null;
             }
     
             @Override
             public long getItemId(int position) {
                 return 0;
             }
     
             @Override
             public View getView(int position, View convertView, ViewGroup parent) {
                 View inflate = getLayoutInflater().inflate(R.layout.lisetitem_open_log, null);
                 TextView textView_useName = (TextView) inflate.findViewById(R.id.textView_useName);
                 TextView textView_time = (TextView) inflate.findViewById(R.id.textView_time);
                 textView_useName.setText(openLogList.get(position).getUser());
                 textView_time.setText(openLogList.get(position).getTime());
                 return inflate;
             }
         }

    private boolean isSleep =false;

    @Override
    protected void onStart() {
        super.onStart();
        if (isSleep){
            Intent intent = new Intent();
            intent.setClass(OpenLogActivity.this,LockActivity.class);
            intent.putExtra("sleep","sleep");
            startActivityForResultTo(intent, Constant.REQUEST_RESULT.IS_SLEEP);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        isSleep=true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == Constant.REQUEST_RESULT.IS_SLEEP && resultCode == Constant.REQUEST_RESULT.IS_SLEEP){
            isSleep = false;
        }
    }
}
